<?php
include "./config/config.inc.php";

$bidamount = array(); //initialize an empty array for bid addition
$altamount = array(); //initialze an empty array for alternate bid addition
$altamounttotal = 0;
$bidamounttotal = 0;

//connect to mysql database
mysql_connect($host, $username, $password);
@mysql_select_db($database) or die("Unable to select database");


//sorting if statements
//Bid id if's

if ($_GET['sort'] == 1)
    $query = "SELECT * FROM bids ORDER BY bid_id DESC";
elseif ($_GET['sort'] == 2)
    $query = "SELECT * FROM bids ORDER BY bid_id ASC";
//Project if's
elseif ($_GET['sort'] == 3)
    $query = "SELECT * FROM bids ORDER BY project DESC";
elseif ($_GET['sort'] == 4)
    $query = "SELECT * FROM bids ORDER BY project ASC";
//Generial contractor if's
elseif ($_GET['sort'] == 5)
    $query = "SELECT * FROM bids ORDER BY general_con DESC";
elseif ($_GET['sort'] == 6)
    $query = "SELECT * FROM bids ORDER BY general_con ASC";
//bid date if's
elseif ($_GET['sort'] == 7)
    $query = "SELECT * FROM bids ORDER BY bid_date DESC";
elseif ($_GET['sort'] == 8)
    $query = "SELECT * FROM bids ORDER BY bid_date ASC";
//bid date if's
elseif ($_GET['sort'] == 9)
    $query = "SELECT * FROM bids ORDER BY bid_amount DESC";
elseif ($_GET['sort'] == 10)
    $query = "SELECT * FROM bids ORDER BY bid_amount ASC";
else
    $query = "SELECT * FROM bids";
//end of sorting statements


$result = mysql_query($query);

$num = mysql_numrows($result);

mysql_close();


$i = 0;
$e = 0;
while ($e < $num) {
    $bidamount[$e] = mysql_result($result, $e, "bid_amount");
    $altamount[$e] = mysql_result($result, $e, "bid_alternates");
    $altamounttotal = $altamounttotal + $altamount[$e];
    $bidamounttotal = $bidamounttotal + $bidamount[$e];
    $e++;
}
?>


  <title>Project Details</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/style/detail.css" >

  <!-- Hack to avoid flash of unstyled content in IE -->
  <script> </script>
  <script type="text/javascript" src="/browser_detect.js"></script>
  <script type="text/javascript" src="/popup.js"></script>
</head><body id="onecolumn">
  <div id="container">
    <div class="wrapper">
      <div id="header">
        <div class="wrapper">
          <h1 id="page-title"><div id="g_title">Projects
		  <div id="price">
		  <?php
echo "<p><b>Total: $$bidamounttotal</b></p>";
echo "<p>Alt Total: $$altamounttotal</b></p>";
?>	
		  </div>
					  
		  </div></h1>
		  <div style="clear: both;"></div>

          <p class="description"><a href="/">|Home|</a><a href="./new/">|New Job|</a><a href="./Contacts/">|Contacts|</a>
		  <form action="search.php" method="post">
			Search: <input type="text" name="bidid" />
		  </form>
		  </p>
		  <div id="g_description">
		  	  

		  </div>
          <div style="clear: both;"></div>
        </div>
      </div>
      <!-- /editable --><!-- /wrapper --><!-- /header -->
      <div id="main-content">
        
        <div class="wrapper">
          <div class="content-item">
			</div>
			<div id="g_body">
				<table width='%100' border='1'>
					<tr>
						<td>
							<b>BID Number</b>
							<a href='index.php?sort=1'><img width='5' alt='Ascend' src=./images/up.gif /></a>
							<a href='index.php?sort=2'><img width='5' alt='Descend' src=./images/down.gif /></a>
						</td> 
						<td>
							<b>Project Name</b>
							<a href='?sort=3'><img width='5' alt='Ascend' src=./images/up.gif /></a>
							<a href='?sort=4'><img width='5' alt='Descend' src=./images/down.gif /></a>
						</td> 
						<td>
							<b>Bid Date</b>
							<a href='?sort=7'><img width='5' alt='Ascend' src=./images/up.gif /></a>
							<a href='?sort=8'><img width='5' alt='Descend' src=./images/down.gif /></a>
						</td>
						<td>
						<b>City</b>
						</td>						
						<td>
							<b>BID Amount</b>
							<a href='?sort=9'><img width='5' alt='Ascend' src=./images/up.gif /></a>
							<a href='?sort=10'><img width='5' alt='Descend' src=./images/down.gif /></a>
						</td> 
						<td>
							<b>Alternate Amount</b>
						</td> 
						<td>
							<b>General Contractor</b>
							<a href='?sort=5''><img width='5' alt='Ascend' src=./images/up.gif /></a>
							<a href='?sort=6''><img width='5' alt='Descend' src=./images/down.gif /></a>	
						</td>
					</tr>
			<?php
while ($i < $num) {
    $project = mysql_result($result, $i, "project");
    $Bidid = mysql_result($result, $i, "BID_id");
    $biddate = mysql_result($result, $i, "bid_date");
	$contact=mysql_result($result, $i,"General_con");
	$bidamount = mysql_result($result, $i, "bid_amount");
    $altamount = mysql_result($result, $i, "bid_alternates");
	$status = mysql_result($result, $i, "Status");
	$city = mysql_result($result, $i, "city");
	
	if($status ==1)$statustxt = "Yellow";//Pending
	if($status ==2)$statustxt = "Red";//bid lost
	if($status ==3)$statustxt = "Green";// bid won
	if($status ==4)$statustxt = "Blue";//no bid
	
	$htmlview = "./minidetails.php?bidid=$Bidid";
    echo "
					<tr>
					<td>$Bidid</td> <td bgcolor='$statustxt'><a onfocus='this.blur()' title='' onmouseover=popup('$htmlview') onmouseout='kill()' href='./details.php?bidid=$Bidid'>$project</a></td><td>$biddate</td><td>$city</td><td>$$bidamount</td><td>$$altamount</td><td>$contact</td>
					</tr>
					";

    $i++;
}
?>
			</table>
			</div>
		  </div>
          <div style="clear: both;"></div>
        </div>
      </div>
      <!-- /wrapper --><!-- /main-content -->
      <div id="footer"><div class="wrapper">
        <hr>
        <p></p><div id="g_footer">

			   </div>
        <div style="clear: both;"></div>
      </div></div>
      <!-- /wrapper --><!-- /footer -->
    </div>
  </div>
<!-- /wrapper --><!-- /container -->

<div id="extraDiv1"><span></span></div><div id="extraDiv2"><span></span></div>
<div id="extraDiv3"><span></span></div><div id="extraDiv4"><span></span></div>
<div id="extraDiv5"><span></span></div><div id="extraDiv6"><span></span></div>

</body></html>


